﻿using MediatR;
using MS.Data.API.Write.Applicant.Command;
using MS.Data.Domain;
using MS.Data.ErrorCode;
using MS.Data.Infratructrue.Istanbul;

namespace MS.Data.API.Write.Applicant.CommandHandel
{
    /// <summary>
    /// 添加权限信息命令处理
    /// </summary>
    public class AddPermissionCommandHandel : IRequestHandler<AddPermissionCommand, APIResult<int>>
    {
        /// <summary>
        /// 权限
        /// </summary>
        IBaseRepository<Permission> perRep;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="perRep">权限</param>
        public AddPermissionCommandHandel(IBaseRepository<Permission> perRep)
        {
            this.perRep = perRep;
        }
        /// <summary>
        ///  处理
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>返回权限添加结果</returns>
        public async Task<APIResult<int>> Handle(AddPermissionCommand request, CancellationToken cancellationToken)
        {
            await perRep.Add(request.PermissionData);

            return new APIResult<int>()
            {
                code=APIEnum.添加成功,
                mes="",
                data=1
            };
        }
    }
}
